//
//  HMSCChannelView.m
//  HowToDo
//
//  Created by 胡坤 on 2017/1/6.
//  Copyright © 2017年 KY. All rights reserved.
//

#import "HMSCChannelView.h"
#import "UIButton+extension.h"
@interface HMSCChannelView ()
@property(nonatomic,strong)UIButton *leftListBtn;
@property(nonatomic,strong)UIButton *rightFunctionBtn;
@end

@implementation HMSCChannelView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self setUPUI];
    }
    return self;
}
-(void)setUPUI
{
    CALayer *layer = [self layer];
    layer.borderWidth = 1;
    layer.borderColor = [UIColor lightGrayColor].CGColor;
    UIView* lineView = [[UIView alloc]init];
    lineView.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.centerX.equalTo(self);
         make.width.mas_equalTo(1);
         make.top.bottom.equalTo(self);
     }];
    [self.leftListBtn addTarget:self action:@selector(showListView:) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:self.leftListBtn];
    
    [self.leftListBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(self);
        make.right.equalTo(lineView.mas_left);
    }];
    [self.rightFunctionBtn addTarget:self action:@selector(functionBtnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    //设置
    [self.rightFunctionBtn setImage:[UIImage imageNamed:@"subscribe_audio_cancel_download"] forState:UIControlStateSelected];
    [self.rightFunctionBtn setTitle:@"取消" forState:UIControlStateSelected];
    [self addSubview:self.rightFunctionBtn];
    [self.rightFunctionBtn mas_makeConstraints:^(MASConstraintMaker *make)
    {
        make.top.right.bottom.equalTo(self);
        make.left.equalTo(lineView);
    }];
}

- (void)showListView:(UIButton *)sender
{
    self.clickListBtn();
}
- (void)functionBtnClickAction:(UIButton *)sender
{
    sender.selected = !sender.selected;
    self.clickFunctionBtn(sender.selected);
}
- (void)setIsLoading:(BOOL)isLoading
{
    _isLoading = isLoading;
    self.rightFunctionBtn.selected = isLoading;
    if (isLoading)
    {
        [self functionBtnClickAction:self.rightFunctionBtn];
    }
}
- (UIButton *)leftListBtn
{
    if (!_leftListBtn)
    {
         _leftListBtn = [UIButton buttonWithTitle:@"列表" NorTitleColor:[UIColor lightGrayColor] SelColor:[UIColor orangeColor] ImgName:@"sub_list"];
    }
    return _leftListBtn;
}
- (UIButton *)rightFunctionBtn
{
    if (!_rightFunctionBtn)
    {
        _rightFunctionBtn = [UIButton buttonWithTitle:@"下载" NorTitleColor:[UIColor lightGrayColor] SelColor:[UIColor lightGrayColor] ImgName:@"new_today_audio_download_icon"];
    }
    return _rightFunctionBtn;
}

@end
